function changeUserIsDes()
{
	userIsDes = false;
	var f = document.getElementById('f');
	var y = Number(f.year.value);
	var m = Number(f.month.value);
	var d = Number(f.day.value);
	var userId = Number(f.user_id.value);
	if(users_des[userId] && users_des[userId] <= _dateToDb(y + '-' + m + '-' + d))
	{
		userIsDes = true;
	}
}

function changeSumm(input)
{
	if(input.form.vos_marta_summ) input.form.vos_marta_summ.value = getNumber(input.value);
	input.form.ng_summ.value = getNumber(input.value);
	input.form.ref_summ.value = getNumber(input.value);
	input.form.des_summ.value = getNumber(input.value);
	input.form.platezh_summ.value = getNumber(input.value);
}

function changeValuta(s)
{
	if(document.getElementById('8marta_valuta')) document.getElementById('8marta_valuta').innerHTML = s.options[s.selectedIndex].text;
	document.getElementById('ng_valuta').innerHTML = s.options[s.selectedIndex].text;
	document.getElementById('ref_valuta').innerHTML = s.options[s.selectedIndex].text;
	document.getElementById('des_valuta').innerHTML = s.options[s.selectedIndex].text;
	s.form.platezh_valuta.selectedIndex = s.selectedIndex;
	s.form.ref_depo_valuta.selectedIndex = s.selectedIndex;
}

function changeIsBonus(ch)
{
	if(ch.form.add_8marta) ch.form.add_8marta.disabled = ch.checked;
	ch.form.add_ref.disabled = ch.checked;
	ch.form.add_des.disabled = ch.checked;
	ch.form.add_ng.disabled = ch.checked;
	if(ch.checked)
	{
		if(ch.form.add_8marta) ch.form.add_8marta.checked = false;
		ch.form.add_ref.checked = false;
		ch.form.add_des.checked = false;
		ch.form.add_ng.checked = false;
		changeIsPlatezh(false);
	}
	var div1 = DOM.next(ch.parentNode, "DIV");
	var div2 = DOM.next(div1, "DIV");
	var div3 = DOM.next(div2, "DIV");
	var div4 = DOM.next(div3, "DIV");
	var div5 = DOM.next(div3, "DIV");
	div1.style.display = ch.checked ? "" : 'none';
	div2.className = ch.checked ? "gray" : '';
	div3.className = ch.checked ? "gray" : '';
	div4.className = ch.checked ? "gray" : '';
	if(div5) div5.className = ch.checked ? "gray" : '';
	changeAddNg(ch.form.add_ng);
	changeAddRef(ch.form.add_ref);
	changeAddDes(ch.form.add_des);
	if(ch.form.add_8marta) changeAdd8marta(ch.form.add_8marta);
}

function changeAddRef(ch)
{
	document.getElementById('ref_summ').style.display = ch.checked ? '' : 'none';
	document.getElementById('ref_to_depo_block').style.display = ch.checked ? 'block' : 'none';
	if(!ch.checked) document.getElementById('f').ref_to_depo.checked = false; 
	changeRefDepo(document.getElementById('f').ref_to_depo);
}

function changeAddDes(ch)
{
	document.getElementById('des_summ').style.display = ch.checked ? '' : 'none';
	document.getElementById('des_to_depo_block').style.display = ch.checked ? 'block' : 'none';
	if(!ch.checked) document.getElementById('f').des_to_depo.checked = false; 
	changeDesDepo(document.getElementById('f').des_to_depo);
}

function changeAddNg(ch)
{
	document.getElementById('ng_summ').style.display = ch.checked ? '' : 'none';
}

function changeAdd8marta(ch)
{
	document.getElementById('8marta_summ').style.display = ch.checked ? '' : 'none';
}

function changeRefDepo(ch)
{
	document.getElementById('ref_to_depo_block2').style.display = ch.checked ? 'block' : 'none';
}

function changeDesDepo(ch)
{
	document.getElementById('des_to_depo_block2').style.display = ch.checked ? 'block' : 'none';
}


function addSchet()
{
	var f = document.getElementById('f');
		if(f.platezh_to_user_id.value == String(meId))
		{
			openPop(230);
			var pop = document.getElementById('pop');
			var frame = document.createElement('IFRAME')
			frame.width = 400;
			frame.height = 250;
			frame.frameborder = 0;
			frame.src = base_url + 'schet/add_small/';
			frame.style.border = 'none';
			pop.appendChild(frame);
		}
		else
		{
			alert('Вы можете добавить счёт только для себя');
		}
}

function updateSchet(user_id, selected_last)
{
	closePop();
	changeSchet();
	$.ajax({
		url: base_url + 'ajax/get_scheta/' + user_id,
		type: 'GET',
		data: {},
		success: function(data)
		{						
			var f = document.getElementById('f');
			var rows = data.split("\n");
			num = 0;
			var selectedIndex = 0;
			for(var i in rows)
			{
				var s = rows[i].split("|");
				f.platezh_schet_id.options.length = num + 1;
				if(!s[1]) s[1] = '';
				f.platezh_schet_id.options[num] = new Option(s[1], s[0]);
				selectedIndex = num;
				num++;
			}
			if(selected_last)
			{
				f.platezh_schet_id.selectedIndex = selectedIndex;
			}
			changeSchet();
		}
	});
}

function changeIsPlatezh(ch)
{
	document.getElementById('cell_platezh_bank').className = ch ? '' : 'gray';
	document.getElementById('cell_platezh_summ').className = ch ? '' : 'gray';
	document.getElementById('cell_platezh_komiss').className = ch ? '' : 'gray';
	var f = document.getElementById('f');
	f.platezh_schet_id.disabled = !ch;
	f.platezh_to_user_id.disabled = !ch;
	f.platezh_summ.disabled = !ch;
	f.platezh_valuta.disabled = !ch;
	f.platezh_komiss.disabled = !ch;
	DOM.firstChild(DOM.firstChild(document.getElementById('cell_platezh_bank').parentNode.cells[1], "A"), "IMG").src = ch && f.platezh_to_user_id.value == String(meId) ? image_path + 'images/icons/plus.png' : image_path + 'images/icons/plus_disabled.png';
	if(ch)
	{
		f.is_bonus.checked = false;
		changeIsBonus(f.is_bonus);
	}
	changeSchet();
}

function changePlatezhToUser(s)
{
	var img = DOM.firstChild(DOM.firstChild(document.getElementById('cell_platezh_bank').parentNode.cells[1], "A"), "IMG");
	img.src = s.value == meId ? image_path + 'images/icons/plus.png' : image_path + 'images/icons/plus_disabled.png';
	updateSchet(s.value, false);
}

function changeSchet()
{
	var f = document.getElementById('f');
	if(f.platezh_schet_id.options.length > 0 && f.platezh_schet_id.options[f.platezh_schet_id.selectedIndex] && !f.platezh_schet_id.disabled)
	{
		f.hranen.value = 'Счёт десятки ' + trim(f.platezh_to_user_id.options[f.platezh_to_user_id.selectedIndex].text) + " " + f.platezh_schet_id.options[f.platezh_schet_id.selectedIndex].text;
	}
}

function getPlatezhi()
{
	var f = document.getElementById('f');
	var date = f.year.value + "-" + f.month.value + "-" + f.day.value;
	document.getElementById('old_platezhi').innerHTML = '';
	if(f.user_id.value)
	{
		$.ajax({
			url: base_url + 'ajax/get_platezhi_buy/' + date + '/' + f.user_id.value,
			type: 'GET',
			data: {},
			success: function(data)
			{						
				var rows = data.split("\n");
				var txt = '';
				for(var i in rows)
				{
					var p = rows[i].split("|");
					if(p[1])
					{
						var pTxt = p[1].split(' - ');
						txt += "<input type='radio' name='platezh_id' value='" + p[0] + "' onclick=\"changeIsPlatezh(false); this.form.hranen.value = '" + pTxt[1] + "'\"> " + p[1] + "<br>";
					}
					document.getElementById('old_platezhi').innerHTML = txt;
				}
			}
		});
	}
}

